package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Resource
    private IFollowService followService;

    /**
     * 关注/取关用户
     * @param followUserId 要关注的用户id
     * @param isFollow true 关注 false 取关
     * @return
     */
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable(name = "id") Long followUserId, @PathVariable(name = "isFollow") Boolean isFollow) {
        return followService.follow(followUserId, isFollow);
    }

    /**
     * 查询是否关注了followUserId
     * @param followUserId 要查询关注状态的用户id
     * @return
     */
    @GetMapping("/or/not/{id}")
    public Result queryFollowStatus(@PathVariable(name = "id") Long followUserId) {
        return followService.queryFollowStatus(followUserId);
    }

    /**
     * 查询当前用户和targetUserId (目标用户) 共同关注的人
     * @param targetUserId 目标用户
     * @return
     */
    @GetMapping("/common/{id}")
    public Result queryCommonFollows(@PathVariable(name = "id") Long targetUserId) {
        return followService.queryCommonFollows(targetUserId);
    }

}
